package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.UserDto;
import com.qk.entity.User;
import com.qk.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping
    public Result list(UserDto userDto){
        log.info("查询用户列表 {}", userDto);
        PageResult<User> pageResult = userService.list(userDto);
        return Result.success(pageResult);
    }
    @PostMapping
    public Result addUser(@RequestBody User user){
        log.info("添加用户 {}", user);
        userService.addUser(user);
        return Result.success();
    }
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<String> ids){
        log.info("删除用户 {}", ids);
        userService.deleteById(ids);
        return Result.success();
    }

}
